package nyist.media.config;

import freemarker.template.Configuration;
import freemarker.template.TemplateModelException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;

import javax.annotation.PostConstruct;
import javax.servlet.ServletContext;

/**
 * @author wangshuai
 * freemarker配置
 */
@org.springframework.context.annotation.Configuration
public class FreemarkerConfig {

    @Bean
    public MyFreemarkerVariable freemarkerVariables() {
        return new MyFreemarkerVariable();
    }

    class MyFreemarkerVariable {

        @Autowired
        private Configuration configuration;
        @Autowired
        private ServletContext servletContext;
//        @Autowired
//        private CurrencyMethod currencyMethod;
//        @Autowired
//        private MessageMethod messageMethod;
//        @Autowired
//        private AbbreviateMethod abbreviateMethod;

        /**
         * 容器启动执行初始化
         *
         * @throws TemplateModelException 异常对象
         */
        @PostConstruct
        public void setSharedVariable() throws TemplateModelException {
//            configuration.setSharedVariable("currency", currencyMethod);
//            configuration.setSharedVariable("message", messageMethod);
//            configuration.setSharedVariable("abbreviate", abbreviateMethod);
            configuration.setSharedVariable("locale", "zh_CN");
            configuration.setSharedVariable("project_name", "多媒体教室管理系统");
            configuration.setSharedVariable("base", servletContext.getContextPath());
        }
    }

}